package com.example.android.common.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;
import com.example.android.cardemulation.R;
import com.example.android.common.Entity.ShopCard;

import java.util.ArrayList;

/**
 * Created by Joe on 2016/6/30.
 */
public class MyAdapter extends BaseAdapter {
    private ArrayList<ShopCard> mData;
    private Context mContext;
    @Override
    public int getCount() {
        return mData.size();
    }
    public MyAdapter(ArrayList<ShopCard> mData,Context mContext){
        this.mData = mData;
        this.mContext = mContext;
    }

    @Override
    public Object getItem(int position) {
        return null;
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder = null;
        if(convertView ==null){
            convertView = LayoutInflater.from(mContext).inflate(R.layout.item_list_shop_card,parent,false);
            holder = new ViewHolder();
            holder.txt_name = (TextView) convertView.findViewById(R.id.item_shop_card_name);
            convertView.setTag(holder);  //将holder存储到convertView中
        }else{
            holder = (ViewHolder) convertView.getTag();
        }
        holder.txt_name.setText(mData.get(position).getName());
        return convertView;
    }
    static class ViewHolder{
        TextView txt_name;
    }
}
